<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\index\controller;
/**
 * 职位控制器
 */
class Position extends IndexBase
{   
	 /**
     * 职位分类添加
     */
    public function positionCatAdd()
    {
        
        IS_POST && $this->jump($this->logicPosition->positionCatEdit($this->param));
		$pid=!empty($this->param['pid'])?$this->param['pid']:0;	
        $this->assign('pid',$pid);
		$name=db("position_cat")->where("id=".$pid)->value("catname");
		$this->assign('name',!empty($name)?$name:'顶级分类');
        return $this->fetch('position_cat_edit');
    }    
    /**
     * 职位分类编辑
     */
    public function positionCatEdit()
    {
        
        IS_POST && $this->jump($this->logicPosition->positionCatEdit($this->param));
        
        $info = $this->logicPosition->getPositionCatInfo(['id' => $this->param['id']]);
        $name=db("position_cat")->where("id=".$info['pid'])->value("catname");
		$this->assign('name',!empty($name)?$name:'顶级分类');
        $this->assign('info', $info);
        $this->assign('pid', $info['pid']);
        return $this->fetch('position_cat_edit');
    }
	 /**
     * 发布职位列表
     */
    public function workList()
    {
		$where = $this->logicPosition->getWhere($this->param);
        $list=$this->logicPosition->getWorkList($where);
        foreach($list as $k=>$v){
            $list[$k]['td']=db("deliver_resume")->where('work_id',$v['id'])->count();
        }
        $this->assign('list', $list);   
        return $this->fetch('work_list');
    }
	 /**
     * 职位详情
     */
    public function workInfo()
    {
        $info=$this->logicPosition->getWorkInfo(['id' => $this->param['id']]);
		if(!empty($info['position_id'])){
			$info['positionName']=db('position_cat')->where('id',$info['position_id'])->value('catname');
		}	
		if(!empty($info['education_id'])){
			$info['education']=db('education')->where('education_id',$info['education_id'])->value('name');
		}else{
            $info['education']='不限';
        }
		if(!empty($info['experience_id'])){
			$info['experience']=db('experience')->where('experience_id',$info['experience_id'])->value('name');
		}else{
			$info['experience']='不限';
		}
        $info['company']=db('company')->where('user_id',$info['user_id'])->value('company');
        //$info['cont']=preg_replace("/(\s|\&nbsp\;|　|\xc2\xa0)/", " ", strip_tags($info['cont']));
        $this->assign('info', $info);   
        return $this->fetch('workInfo');
    }
    /**
     * 职位分类列表
     */
    public function position_cat()
    {
		$pid=!empty($this->param['pid'])?$this->param['pid']:0;		
		$name=db("position_cat")->where("id=".$pid)->value("catname");
        $this->assign('list', $this->logicPosition->getPositionCatList(array('pid'=>$pid)));   
		$this->assign('name',!empty($name)?$name:'顶级分类');
		$this->assign('pid',$pid);
        return $this->fetch('position_cat_list');
    }
	/**
     * 职位分类删除
     */
    public function positionCatDel($id = 0)
    {
        $is=db("position_cat")->where("status=0 and pid=".$id)->value("id");
		if(!empty($is)){
			return ['error', '分类下存在子分类，不能删除'];
		}else{
			$this->jump($this->logicPosition->positionCatDel(['id' => $id]));
		}      
    }
	/**
     * 职位删除
     */
    public function workDel($id = 0)
    {
		$this->jump($this->logicPosition->workDel($id));
   
    }
	/**
     * 排序
     */
    public function setSort()
    {
        
        $this->jump($this->logicAdminBase->setSort('Position_cat', $this->param));
    }
	/**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('Work', $this->param));
    }

}
